package net.nshc.kwkim.mycalc.activity;

import net.nshc.kwkim.mycalc.*;
import android.content.*;
import android.os.*;
import android.preference.*;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.*;

public class SettingPreference extends PreferenceActivity {
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preference);

		PreferenceManager pref = getPreferenceManager();
		pref.setSharedPreferencesName("pref");
		pref.setSharedPreferencesMode(MODE_PRIVATE);
		
		CheckBoxPreference pref1 = (CheckBoxPreference)findPreference("pref_sound");
		CheckBoxPreference pref2 = (CheckBoxPreference)findPreference("pref_location");
		CheckBoxPreference pref3 = (CheckBoxPreference)findPreference("pref_voice");
		ListPreference pref4 = (ListPreference)findPreference("pref_font");
		pref1.setOnPreferenceClickListener(mOnPreferenceClickListener);
		pref2.setOnPreferenceClickListener(mOnPreferenceClickListener); 
		pref3.setOnPreferenceClickListener(mOnPreferenceClickListener); 
		pref4.setOnPreferenceClickListener(mOnPreferenceClickListener); 
		
		SharedPreferences pre;
		pre = getSharedPreferences("pref",0);
		pref1.setChecked(pre.getBoolean("pref_sound", true));
		pref2.setChecked(pre.getBoolean("pref_location", true));
		pref3.setChecked(pre.getBoolean("pref_voice", true));
		pref4.setValue(pre.getString("pref_font","16"));
	}

	Preference.OnPreferenceClickListener mOnPreferenceClickListener = new OnPreferenceClickListener() { 
		public boolean onPreferenceClick(Preference preference) { 
			
			if ( preference.getKey().equals("pref_sound")) {
				
				boolean bSound = preference.getSharedPreferences().getBoolean("pref_sound", false);
				if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_PREFERENCE,"Click CheckPreference : "+bSound);
				MyCalcActivity.bSound = bSound;
				
			} else if ( preference.getKey().equals("pref_location")) {
				
				boolean bLocation = preference.getSharedPreferences().getBoolean("pref_location", false);
				if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_PREFERENCE,"Click CheckPreference : "+bLocation);
				MyCalcActivity.bLocation = bLocation;
				
			} else if ( preference.getKey().equals("pref_voice")) {
				
				boolean bVoice = preference.getSharedPreferences().getBoolean("pref_voice", false);
				if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_PREFERENCE,"Click CheckPreference : "+bVoice);
				MyCalcActivity.bVoice = bVoice;
				
			} else if ( preference.getKey().equals("pref_font")) {
				
				String iSize = preference.getSharedPreferences().getString("pref_font", "16");
				if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_PREFERENCE,"Click CheckPreference : "+iSize);
				MyCalcActivity.iSize = Integer.parseInt(iSize);
				
			}
			
			return false; 
		} 
	};
}
